#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
void solve()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n + 1), sum(n + 1), power(222);
    for (ll i = 1; i <= n;i++)
    {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }

    ll cnt = 0, now = 1;
    power[0] = 1;
    if(k==1||k==-1)
    {
        if(k==-1)
        {
            power[++cnt] = -1;
        }
    }
    else 
    {
        while(now<1e14)
        {
            now *= k;
            power[++cnt] = now;
        }
    }

    map<ll, ll> mp;
    for (ll i = 0; i <= cnt;i++)
    {
        mp[power[i] + 0]++;
    }

    ll ans = 0;
    for (ll i = 1; i <= n;i++)
    {
        ans += mp[sum[i]];
        for (ll j = 0; j <= cnt;j++)
        {
            mp[sum[i] + power[j]]++;
        }
    }

    cout << ans << endl;
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
